<?php

namespace style;

/**
 * Created by 豆豆.
 * User: longrbl@163.com
 * Date: 2016/9/12
 * Time: 22:48
 */
use style\lib;

class longrbl
{
  /**
   * 系统初始化
   */
  static public function run($http, $response, $service)
  {
    if (empty($response)) {
      return;
    }
    if (empty($http)) {
      return;
    }
    try {
      $request = new lib\request($http, $response, $service);
      $request->run();
    } catch (\Exception $e) {
      throw new \Exception($e->getMessage());
    }
  }


  /**
   * 异步处理数据的控制器初始化函数
   * @param $data 要处理的数据json格式
   * @param $service swoole 实例对象
   */
  static public function task_tun($data, $service, $task_service)
  {
    if (empty($data) && empty($service)) {
      throw new \Exception('task,数据或swoole实例对象为空');
    }
    try {
      $task = new lib\Task_request($data, $service, $task_service);
      $task->run();
    } catch (\Exception $e) {
      throw new \Exception($e->getMessage());
    }
  }

  /**
   * @param $class
   * @return 自动加载类
   */
  static public function louad($class)
  {
    try {
      $class = str_replace('\\', '/', $class);
      $path = APP . '/' . $class . '.php';
      if (is_file($path)) {
        include_once $path;
      }
    } catch (\Exception $e) {
      throw new \Exception('自动加载有错误' . $e);
    }
  }


}